package com.hongkzh.www.friend.controller;

import com.auth0.jwt.interfaces.Claim;
import com.google.common.collect.Lists;
import com.hongkzh.www.adv.service.AdvService;
import com.hongkzh.www.conmon.*;
import com.hongkzh.www.friend.service.FriendService;
import com.hongkzh.www.swagger.annotation.*;
import com.jfinal.aop.Before;
import com.jfinal.aop.Clear;
import com.jfinal.kit.PropKit;
import com.jfinal.kit.StrKit;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.Record;
import com.jfinal.plugin.activerecord.tx.Tx;
import com.jfinal.upload.UploadFile;

import java.util.List;
import java.util.Map;

/**
 * @author martins
 */
@Api(tag = "friend", description = "乐友接口")
public class FriendController extends BaseController {
    /**
     * 上传文件基础虚拟路径
     */
    public static final String USERFILES_BASE_URL = "/userfiles/1/images/hkMediaCategoryCircle/";
    /**
     * 上传文件基础虚拟路径
     */
    public static final String USERFILES_POST_BASE_URL = "/userfiles/1/images/post/";
    static FriendService friendService=new FriendService();
    static AdvService advService=new AdvService();
    @ApiOperation(url = "/v1/friend/friendList", tag = "friend", httpMethod = "post",description = "乐友-好友列表")
    @Params({
            @Param(name = "loginUid", description = "当前用户id", required = true, dataType = "string")
    })
    @ApiResponses({
            @ApiResponse(code=200,message="成功",responseHeaders={
                    @ResponseHeader(name="code",description = " 0成功 1失败"),
                    @ResponseHeader(name="data",description = "name 是字母   100表示# list [letter 字母 ,name 名称 level 等级 headImg  头像uid 用户id token 聊天token type 类型  1自媒体 2企业广告3城市广告4传统文化 sex 1男2女"),
                    @ResponseHeader(name="msg",description = "失败原因") })

    })
    public void friendList(){
        String id=getAttr("loginUid");
        ReqResponse<List<Record>> r=new ReqResponse();
        Map<String,List<Record>> friends=friendService.friendList(id);
        List<Record> a= Lists.newArrayList();
        String key;
        for (Map.Entry<String,List<Record>> entry : friends.entrySet()) {
             Record record=new Record();
            key=entry.getKey().replaceAll("\\{","100");
             record.set("name",key);
             record.set("list",entry.getValue());
             a.add(record);

        }

        r.setData(a);
        renderJson(r);
    }
    @ApiOperation(url = "/v1/friend/addFriend", tag = "friend", httpMethod = "post",description = "乐友-增加好友")
    @Params({
            @Param(name = "loginUid", description = "当前用户id", required = true, dataType = "string"),
            @Param(name = "friendId", description = "好友id", required = true, dataType = "string")
    })
    @ApiResponses({
            @ApiResponse(code=200,message="成功",responseHeaders={
                    @ResponseHeader(name="code",description = " 0成功 1失败"),
                    @ResponseHeader(name="data",description = "  "),
                    @ResponseHeader(name="msg",description = "失败原因") })

    })
    @Before(Tx.class)
    public void addFriend(){
        String id=getAttr("loginUid");
        String friendId=getPara("friendId");
        ReqResponse<String> r=new ReqResponse();
        friendService.addFriend(id,friendId);
        r.setData("");
        renderJson(r);
    }
    @ApiOperation(url = "/v1/friend/removeFriend", tag = "friend", httpMethod = "post",description = "乐友-删除好友")
    @Params({
            @Param(name = "loginUid", description = "当前用户id", required = true, dataType = "string"),
            @Param(name = "friendId", description = "好友id", required = true, dataType = "string")
    })
    @ApiResponses({
            @ApiResponse(code=200,message="成功",responseHeaders={
                    @ResponseHeader(name="code",description = " 0成功 1失败"),
                    @ResponseHeader(name="data",description = "  "),
                    @ResponseHeader(name="msg",description = "失败原因") })

    })
    @Before(Tx.class)
    public void removeFriend(){
        String id=getAttr("loginUid");
        String friendId=getPara("friendId");
        ReqResponse<String> r=new ReqResponse();
        friendService.removeFriend(id,friendId);
        r.setData("");
        renderJson(r);
    }
    @ApiOperation(url = "/v1/friend/addBlack", tag = "friend", httpMethod = "post",description = "乐友-增加黑名单")
    @Params({
            @Param(name = "loginUid", description = "当前用户id", required = true, dataType = "string"),
            @Param(name = "friendId", description = "好友id", required = true, dataType = "string")
    })
    @ApiResponses({
            @ApiResponse(code=200,message="成功",responseHeaders={
                    @ResponseHeader(name="code",description = " 0成功 1失败"),
                    @ResponseHeader(name="data",description = "  "),
                    @ResponseHeader(name="msg",description = "失败原因") })

    })
    @Before(Tx.class)
    public void addBlack(){
        String id=getAttr("loginUid");
        String friendId=getPara("friendId");
        ReqResponse<String> r=new ReqResponse();
        if(StrKit.isBlank(friendId)){
            r.setCode(1);
            r.setMsg("好友id必填");
        }
        else {
            try {
                friendService.addBlack(id, friendId);
            } catch (Exception e) {
                e.printStackTrace();
                r.setCode(1);
                r.setMsg("添加失败");
            }
        }
        renderJson(r);
    }
    @ApiOperation(url = "/v1/friend/removeBlack", tag = "friend", httpMethod = "post",description = "乐友-删除黑名单")
    @Params({
            @Param(name = "loginUid", description = "当前用户id", required = true, dataType = "string"),
            @Param(name = "friendId", description = "好友id", required = true, dataType = "string")
    })
    @ApiResponses({
            @ApiResponse(code=200,message="成功",responseHeaders={
                    @ResponseHeader(name="code",description = " 0成功 1失败"),
                    @ResponseHeader(name="data",description = "  "),
                    @ResponseHeader(name="msg",description = "失败原因") })

    })
    @Before(Tx.class)
    public void removeBlack(){
        String id=getAttr("loginUid");
        String friendId=getPara("friendId");
        ReqResponse<String> r=new ReqResponse();
        try {
            friendService.removeBlack(id,friendId);
        } catch (Exception e) {
            r.setCode(1);
            r.setMsg("删除失败");
        }
        r.setData("");
        renderJson(r);
    }




    @ApiOperation(url = "/v1/friend/blackList", tag = "friend", httpMethod = "post",description = "乐友- 黑名单列表")
    @Params({
            @Param(name = "loginUid", description = "当前用户id", required = true, dataType = "string"),
            @Param(name = "pageNumber", description = "页码", required = true, dataType = "string")
    })
    @ApiResponses({
            @ApiResponse(code=200,message="成功",responseHeaders={
                    @ResponseHeader(name="code",description = " 0成功 1失败"),
                    @ResponseHeader(name="data",description = " name 名称 level 等级 headImg  头像uid 用户id token 聊天token type 类型  1自媒体 2企业广告3城市广告4传统文化 sex 1男2女  "),
                    @ResponseHeader(name="msg",description = "失败原因") })

    })
    public void blackList(){
        String id=getAttr("loginUid");
        int pageNumber=getParaToInt("pageNumber");
        ReqResponse<Page<Record>> r=new ReqResponse();

            r.setData(friendService.blackList(id,pageNumber));


        renderJson(r);
    }

    @ApiOperation(url = "/v1/friend/circleList", tag = "friend", httpMethod = "post",description = "乐友-用户圈子列表")
    @Params({
            @Param(name = "loginUid", description = "当前用户id", required = true, dataType = "string")
    })
    @ApiResponses({
            @ApiResponse(code=200,message="成功",responseHeaders={
                    @ResponseHeader(name="code",description = " 0成功 1失败"),
                    @ResponseHeader(name="data",description = " name 是字母   100表示# list [ letter 字母  coverImgSrc 图片 circleId 圈子id circleName 圈子名称categoryName 圈子分类 userCount圈子人数"),
                    @ResponseHeader(name="msg",description = "失败原因") })

    })
    public void circleList(){
        String id=getAttr("loginUid");
        ReqResponse<List<Record> > r=new ReqResponse();
        Map<String,List<Record>>  friends=friendService.circleList(id);
        List<Record> a= Lists.newArrayList();
        String key;
        for (Map.Entry<String,List<Record>> entry : friends.entrySet()) {
            Record record=new Record();
            key=entry.getKey().replaceAll("\\{","100");
            record.set("name",key);
            record.set("list",entry.getValue());
            a.add(record);

        }
        r.setData(a);
        renderJson(r);
    }

    @ApiOperation(url = "/v1/friend/circleCategory", tag = "friend", httpMethod = "post",description = "乐友-圈子广场-圈子分类列表")

    @ApiResponses({
            @ApiResponse(code=200,message="成功",responseHeaders={
                    @ResponseHeader(name="code",description = " 0成功 1失败"),
                    @ResponseHeader(name="data",description = "  categoryId 分类id   name 名称 "),
                    @ResponseHeader(name="msg",description = "失败原因") })

    })
    public void circleCategory(){

        ReqResponse<List<Record> > r=new ReqResponse();
        List<Record>   friends=friendService.circleCategory();
        r.setData(friends);
        renderJson(r);
    }
    @ApiOperation(url = "/v1/friend/circleCategoryList", tag = "friend", httpMethod = "post",description = "乐友-圈子广场-分类圈子列表")
    @Params({
            @Param(name = "loginUid", description = "当前用户id", required = true, dataType = "string"),
            @Param(name = "categoryId", description = "圈子分类id", required = true, dataType = "string")
    })
    @ApiResponses({
            @ApiResponse(code=200,message="成功",responseHeaders={
                    @ResponseHeader(name="code",description = " 0成功 1失败"),
                    @ResponseHeader(name="data",description = "  circleId  circleName名称 coverImgSrc头像 circleCount 圈子人数 ucId   0未加入 "),
                    @ResponseHeader(name="msg",description = "失败原因") })

    })
    public void circleCategoryList(){
        String uid=getAttr("loginUid");
       String categoryId=getPara("categoryId");
        ReqResponse<List<Record> > r=new ReqResponse();
        List<Record>   friends=friendService.circleCategoryList(categoryId,uid);
        r.setData(friends);
        renderJson(r);
    }

    @ApiOperation(url = "/v1/friend/createGroup", tag = "friend", httpMethod = "post",description = "乐友-创建圈子")
    @Params({
            @Param(name = "loginUid", description = "当前用户id", required = true, dataType = "string"),
            @Param(name = "categoryId", description = "分类id", required = true, dataType = "string"),
            @Param(name = "circleName", description = "圈子名称", required = true, dataType = "string"),
            @Param(name = "coverImgSrc", description = "圈子图片", required = true, dataType = "string"),
            @Param(name = "coverImgWidth", description = "封面图片宽", required = true, dataType = "string"),
            @Param(name = "coverImgHeight", description = "封面图片高", required = true, dataType = "string"),
            @Param(name = "introduction", description = "简介", required = true, dataType = "string"),
            @Param(name = "isValidate", description = "是否验证", required = true, dataType = "string"),

    })
    @ApiResponses({
            @ApiResponse(code=200,message="成功",responseHeaders={
                    @ResponseHeader(name="code",description = " 0成功 1失败"),
                    @ResponseHeader(name="data",description = "  "),
                    @ResponseHeader(name="msg",description = "失败原因") })

    })
    public void createGroup(){
        UploadFile uf= getFile("coverImgSrc");
        getResponse().addHeader("Access-Control-Allow-Origin", "*");

        String uid=getAttr("loginUid");
        String categoryId=getPara("categoryId");
        String circleName=getPara("circleName");
        String introduction=getPara("introduction");
        String isValidate=getPara("isValidate");
        String coverImgWidth=getPara("coverImgWidth");
        String coverImgHeight=getPara("coverImgHeight");




        ReqResponse<String> r=new ReqResponse();
        try {
            String coverImgSrc= USERFILES_BASE_URL +DateUtil.FormatDateMMDD()+"/";
            coverImgSrc=getFilePath(coverImgSrc,uf);
            friendService.createGroup(uid,categoryId,circleName,coverImgSrc,introduction,isValidate,coverImgWidth,coverImgHeight);
        }catch (Exception e){
            e.printStackTrace();
            r.setCode(1);
        }
        r.setData("");

            renderJson(r);

    }

    @ApiOperation(url = "/v1/friend/updateGroupCoverImgSrc", tag = "friend", httpMethod = "post",description = "乐友-修改圈子封面")
    @Params({
            @Param(name = "loginUid", description = "当前用户id", required = true, dataType = "string"),
            @Param(name = "circleId", description = "圈子Id", required = true, dataType = "string"),
            @Param(name = "coverImgSrc", description = "圈子图片", required = true, dataType = "string"),
            @Param(name = "coverImgWidth", description = "封面图片宽", required = true, dataType = "string"),
            @Param(name = "coverImgHeight", description = "封面图片高", required = true, dataType = "string"),
    })
    @ApiResponses({
            @ApiResponse(code=200,message="成功",responseHeaders={
                    @ResponseHeader(name="code",description = " 0成功 1失败"),
                    @ResponseHeader(name="data",description = "  "),
                    @ResponseHeader(name="msg",description = "失败原因") })

    })
    public void updateGroupCoverImgSrc(){
        UploadFile uf= getFile("coverImgSrc");
        getResponse().addHeader("Access-Control-Allow-Origin", "*");
        String uid=getAttr("loginUid");
        String circleId=getPara("circleId");

        String coverImgWidth=getPara("coverImgWidth");
        String coverImgHeight=getPara("coverImgHeight");

        ReqResponse<String> r=new ReqResponse();

        try {

            String coverImgSrc= USERFILES_BASE_URL +DateUtil.FormatDateMMDD()+"/";
            coverImgSrc=getFilePath(coverImgSrc,uf);
            friendService.updateGroupCoverImgSrc(uid,circleId,coverImgSrc,coverImgWidth,coverImgHeight);
        }catch (Exception e){
            e.printStackTrace();
            r.setCode(1);
        }
        r.setData("");
        renderJson(r);
    }
    @ApiOperation(url = "/v1/friend/updateGroupValidate", tag = "friend", httpMethod = "post",description = "乐友-修改圈子验证方式")
    @Params({
            @Param(name = "loginUid", description = "当前用户id", required = true, dataType = "string"),
            @Param(name = "circleId", description = "圈子Id", required = true, dataType = "string"),
            @Param(name = "isValidate", description = "1要验证 0否", required = true, dataType = "string"),

    })
    @ApiResponses({
            @ApiResponse(code=200,message="成功",responseHeaders={
                    @ResponseHeader(name="code",description = " 0成功 1失败"),
                    @ResponseHeader(name="data",description = "  "),
                    @ResponseHeader(name="msg",description = "失败原因") })

    })
    public void updateGroupValidate(){
        String uid=getAttr("loginUid");
        String circleId=getPara("circleId");
        String isValidate=getPara("isValidate");

        ReqResponse<String> r=new ReqResponse();
        friendService.updateGroupValidate(uid,circleId,isValidate);
        r.setData("");
        renderJson(r);
    }
    @ApiOperation(url = "/v1/friend/updateGroupUpperLlimit", tag = "friend", httpMethod = "post",description = "乐友-修改圈子上限")
    @Params({
            @Param(name = "loginUid", description = "当前用户id", required = true, dataType = "string"),
            @Param(name = "circleId", description = "圈子Id", required = true, dataType = "string"),
            @Param(name = "upperLlimit", description = "上限", required = true, dataType = "string"),

    })
    @ApiResponses({
            @ApiResponse(code=200,message="成功",responseHeaders={
                    @ResponseHeader(name="code",description = " 0成功 1失败"),
                    @ResponseHeader(name="data",description = "  "),
                    @ResponseHeader(name="msg",description = "失败原因") })

    })
    public void updateGroupUpperLlimit(){
        String uid=getAttr("loginUid");
        String circleId=getPara("circleId");
        String upperLlimit=getPara("upperLlimit");

        ReqResponse<String> r=new ReqResponse();
        friendService.updateGroupUpperLlimit(uid,circleId,upperLlimit);
        r.setData("");
        renderJson(r);
    }
    @ApiOperation(url = "/v1/friend/updateGroupIntroduction", tag = "friend", httpMethod = "post",description = "乐友-修改圈子简介")
    @Params({
            @Param(name = "loginUid", description = "当前用户id", required = true, dataType = "string"),
            @Param(name = "circleId", description = "圈子Id", required = true, dataType = "string"),
            @Param(name = "introduction", description = "简介", required = true, dataType = "string"),

    })
    @ApiResponses({
            @ApiResponse(code=200,message="成功",responseHeaders={
                    @ResponseHeader(name="code",description = " 0成功 1失败"),
                    @ResponseHeader(name="data",description = "  "),
                    @ResponseHeader(name="msg",description = "失败原因") })

    })
    public void updateGroupIntroduction(){
        String uid=getAttr("loginUid");
        String circleId=getPara("circleId");
        String introduction=getPara("introduction");

        ReqResponse<String> r=new ReqResponse();
        friendService.updateGroupIntroduction(uid,circleId,introduction);
        r.setData("");
        renderJson(r);
    }
    @ApiOperation(url = "/v1/friend/updateGroupName", tag = "friend", httpMethod = "post",description = "乐友-修改圈子名称")
    @Params({
            @Param(name = "loginUid", description = "当前用户id", required = true, dataType = "string"),
            @Param(name = "circleId", description = "圈子Id", required = true, dataType = "string"),
            @Param(name = "circleName", description = "名称", required = true, dataType = "string"),

    })
    @ApiResponses({
            @ApiResponse(code=200,message="成功",responseHeaders={
                    @ResponseHeader(name="code",description = " 0成功 1失败"),
                    @ResponseHeader(name="data",description = "  "),
                    @ResponseHeader(name="msg",description = "失败原因") })

    })
    public void updateGroupName(){
        String uid=getAttr("loginUid");
        String circleId=getPara("circleId");
        String circleName=getPara("circleName");

        ReqResponse<String> r=new ReqResponse();
        friendService.updateGroupName(uid,circleId,circleName);
        r.setData("");
        renderJson(r);
    }
    @ApiOperation(url = "/v1/friend/updateGroupCategory", tag = "friend", httpMethod = "post",description = "乐友-修改所属频道")
    @Params({
            @Param(name = "loginUid", description = "当前用户id", required = true, dataType = "string"),
            @Param(name = "categoryId", description = "分类Id", required = true, dataType = "string"),
            @Param(name = "circleId", description = "圈子Id", required = true, dataType = "string"),

    })
    @ApiResponses({
            @ApiResponse(code=200,message="成功",responseHeaders={
                    @ResponseHeader(name="code",description = " 0成功 1失败"),
                    @ResponseHeader(name="data",description = "  "),
                    @ResponseHeader(name="msg",description = "失败原因") })

    })
    public void updateGroupCategory(){
        String uid=getAttr("loginUid");
        String circleId=getPara("circleId");
        String categoryId=getPara("categoryId");

        ReqResponse<String> r=new ReqResponse();
        friendService.updateGroupCategory(uid,circleId,categoryId);
        r.setData("");
        renderJson(r);
    }
    @ApiOperation(url = "/v1/friend/joinGroup", tag = "friend", httpMethod = "post",description = "乐友-加入圈子")
    @Params({
            @Param(name = "loginUid", description = "当前用户id", required = true, dataType = "string"),
            @Param(name = "circleId", description = "圈子Id", required = true, dataType = "string")
    })
    @ApiResponses({
            @ApiResponse(code=200,message="成功",responseHeaders={
                    @ResponseHeader(name="code",description = " 0成功 1失败"),
                    @ResponseHeader(name="data",description = "  "),
                    @ResponseHeader(name="msg",description = "失败原因") })

    })
    @Before(Tx.class)
    public void joinGroup(){

        String uid=getAttr("loginUid");
        String circleId=getPara("circleId");

        ReqResponse<String> r=new ReqResponse();
        try {
            r.setData(friendService.joinGroup(uid,circleId));
        }catch (Exception e){
            e.printStackTrace();
            r.setCode(1);
        }

        renderJson(r);
    }
    @ApiOperation(url = "/v1/friend/confirmJoinGroup", tag = "friend", httpMethod = "post",description = "乐友-管理确认加入圈子")
    @Params({
            @Param(name = "loginUid", description = "当前用户id", required = true, dataType = "string"),
            @Param(name = "uid", description = "用户id", required = true, dataType = "string"),
            @Param(name = "circleId", description = "圈子Id", required = true, dataType = "string")
    })
    @ApiResponses({
            @ApiResponse(code=200,message="成功",responseHeaders={
                    @ResponseHeader(name="code",description = " 0成功 1失败"),
                    @ResponseHeader(name="data",description = "  "),
                    @ResponseHeader(name="msg",description = "失败原因") })

    })
    @Before(Tx.class)
    public void confirmJoinGroup(){

        String uid=getPara("uid");
        String circleId=getPara("circleId");

        ReqResponse<String> r=new ReqResponse();
        try {


            friendService.confirmJoinGroup(uid,circleId);
        }catch (Exception e){
            e.printStackTrace();
            r.setCode(1);
        }
        r.setData("");
        renderJson(r);
    }
    @ApiOperation(url = "/v1/friend/quitGroup", tag = "friend", httpMethod = "post",description = "乐友-退圈子")
    @Params({
            @Param(name = "loginUid", description = "当前用户id", required = true, dataType = "string"),
            @Param(name = "circleId", description = "圈子Id", required = true, dataType = "string")
    })
    @ApiResponses({
            @ApiResponse(code=200,message="成功",responseHeaders={
                    @ResponseHeader(name="code",description = " 0成功 1失败"),
                    @ResponseHeader(name="data",description = "  "),
                    @ResponseHeader(name="msg",description = "失败原因") })

    })
    @Before(Tx.class)
    public void quitGroup(){

        String uid=getAttr("loginUid");
        String circleId=getPara("circleId");

        ReqResponse<String> r=new ReqResponse();
        try {
            friendService.quitGroup(uid,circleId);
        }catch (Exception e){
            e.printStackTrace();
            r.setCode(1);
        }
        r.setData("");
        renderJson(r);
    }
    @ApiOperation(url = "/v1/friend/kickOutGroup", tag = "friend", httpMethod = "post",description = "乐友-踢出圈子")
    @Params({
            @Param(name = "loginUid", description = "当前用户id", required = true, dataType = "string"),
            @Param(name = "uid", description = "用户id", required = true, dataType = "string"),
            @Param(name = "circleId", description = "圈子Id", required = true, dataType = "string")
    })
    @ApiResponses({
            @ApiResponse(code=200,message="成功",responseHeaders={
                    @ResponseHeader(name="code",description = " 0成功 1失败"),
                    @ResponseHeader(name="data",description = "  "),
                    @ResponseHeader(name="msg",description = "失败原因") })

    })
    @Before(Tx.class)
    public void kickOutGroup(){
        String loginUid=getAttr("loginUid");
        String uid=getPara("uid");
        String circleId=getPara("circleId");

        ReqResponse<String> r=new ReqResponse();
        try {
            friendService.kickOutGroup(uid,circleId,loginUid);
        }catch (Exception e){
            e.printStackTrace();
            r.setCode(1);
        }
        r.setData("");
        renderJson(r);
    }
    @ApiOperation(url = "/v1/friend/dismissGroup", tag = "friend", httpMethod = "post",description = "乐友-解除圈子")
    @Params({
            @Param(name = "loginUid", description = "当前用户id", required = true, dataType = "string"),
            @Param(name = "circleId", description = "圈子Id", required = true, dataType = "string")
    })
    @ApiResponses({
            @ApiResponse(code=200,message="成功",responseHeaders={
                    @ResponseHeader(name="code",description = " 0成功 1失败"),
                    @ResponseHeader(name="data",description = "  "),
                    @ResponseHeader(name="msg",description = "失败原因") })

    })
    @Before(Tx.class)
    public void dismissGroup(){
        String uid=getAttr("loginUid");
        String circleId=getPara("circleId");

        ReqResponse<String> r=new ReqResponse();
        try {
            String re=friendService.dismissGroup(uid,circleId);
            if("不是圈主不能解除圈子".equals(re)){
                r.setCode(1);
                r.setMsg(re);
            }
        }catch (Exception e){
            e.printStackTrace();
            r.setCode(1);
        }
        r.setData("");
        renderJson(r);
    }

    @ApiOperation(url = "/v1/friend/getGroupInfo", tag = "friend", httpMethod = "post",description = "乐友-获取圈子信息")
    @Params({
            @Param(name = "loginUid", description = "当前用户id", required = true, dataType = "string"),
            @Param(name = "circleId", description = "圈子Id", required = true, dataType = "string")
    })
    @ApiResponses({
            @ApiResponse(code=200,message="成功",responseHeaders={
                    @ResponseHeader(name="code",description = " 0成功 1失败"),
                    @ResponseHeader(name="data",description = "  name 名称,id,introduction 描述 coverImgSrc 封面图片" +
                            " num 购买展示商品数量 boothMoney 购买展位乐币 state 1未加入2加入 remind 1开启消息提醒0否 categoryId 分类Id categoryName分类名称 userCount 用户人数 " +
                            "isMain 1是群主0不是 isValidate 1是验证 0否 upperLlimit 上限" +
                            "products[productId 产品id  title 产品标题 imgSrc 产品图片 price 产品价格]" +
                            "members[ name 名称,id,headImg 头像 ]" +
                            "posts帖子[postId title 标题 content 内容 isTop 1是置顶0否 isNotice 1是公告0否]"),
                    @ResponseHeader(name="msg",description = "失败原因") })

    })
    public void getGroupInfo(){
        String uid=getAttr("loginUid");
        String circleId=getPara("circleId");
        ReqResponse<Record> r=new ReqResponse();
        try {
            r.setData(friendService.getGroupInfo(uid,circleId));
        }catch (Exception e){
            e.printStackTrace();
            r.setCode(1);
        }
        renderJson(r);
    }
    @ApiOperation(url = "/v1/friend/getGroupMemberInfo", tag = "friend", httpMethod = "post",description = "乐友-获取圈子成员信息")
    @Params({
            @Param(name = "loginUid", description = "当前用户id", required = true, dataType = "string"),
            @Param(name = "circleId", description = "圈子Id", required = true, dataType = "string")
    })
    @ApiResponses({
            @ApiResponse(code=200,message="成功",responseHeaders={
                    @ResponseHeader(name="code",description = " 0成功 1失败"),
                    @ResponseHeader(name="data",description = "  name 名称,id,headImg 头像 state是否圈主"),
                    @ResponseHeader(name="msg",description = "失败原因") })

    })
    public void getGroupMemberInfo(){
        String uid=getAttr("loginUid");
        String circleId=getPara("circleId");
        ReqResponse<List<Record>> r=new ReqResponse();
        try {
            r.setData(friendService.getGroupMemberInfo(uid,circleId));
        }catch (Exception e){
            e.printStackTrace();
            r.setCode(1);
        }
        renderJson(r);
    }
    @ApiOperation(url = "/v1/friend/getProductList", tag = "friend", httpMethod = "post",description = "乐友-个人商品列表")
    @Params({
            @Param(name = "loginUid", description = "当前用户id", required = true, dataType = "string"),
    })
    @ApiResponses({
            @ApiResponse(code=200,message="成功",responseHeaders={
                    @ResponseHeader(name="code",description = " 0成功 1失败"),
                    @ResponseHeader(name="data",description = " productId 产品id  title 产品标题 imgSrc 产品图片 price 产品价格  "),
                    @ResponseHeader(name="msg",description = "失败原因") })

    })
    public void getProductList(){
        String uid=getAttr("loginUid");
        ReqResponse<List<Record>> r=new ReqResponse();
        try {
            r.setData(friendService.getProductList(uid));
        }catch (Exception e){
            e.printStackTrace();
            r.setCode(1);
        }
        renderJson(r);
    }
    @ApiOperation(url = "/v1/friend/addCircleProduct", tag = "friend", httpMethod = "post",description = "乐友-增加圈子商品")
    @Params({
            @Param(name = "loginUid", description = "当前用户id", required = true, dataType = "string"),
            @Param(name = "productId", description = "商品id", required = true, dataType = "string"),
            @Param(name = "circleId", description = "圈子Id", required = true, dataType = "string")
    })
    @ApiResponses({
            @ApiResponse(code=200,message="成功",responseHeaders={
                    @ResponseHeader(name="code",description = " 0成功 1失败"),
                    @ResponseHeader(name="data",description = "   "),
                    @ResponseHeader(name="msg",description = "失败原因") })

    })
    public void addCircleProduct(){
        String uid=getAttr("loginUid");
        String circleId=getPara("circleId");
        String productId=getPara("productId");
        ReqResponse<Record> r=new ReqResponse();
        FriendService friendService2=enhance(FriendService.class);
        try {
            friendService2.addCircleProduct(uid,productId,circleId);
        }catch (Exception e){
            e.printStackTrace();
            r.setCode(1);
        }
        renderJson(r);
    }
    @ApiOperation(url = "/v1/friend/deleteCircleProduct", tag = "friend", httpMethod = "post",description = "乐友-删除圈子商品")
    @Params({
            @Param(name = "loginUid", description = "当前用户id", required = true, dataType = "string"),
            @Param(name = "productId", description = "商品id", required = true, dataType = "string"),
            @Param(name = "circleId", description = "圈子Id", required = true, dataType = "string")
    })
    @ApiResponses({
            @ApiResponse(code=200,message="成功",responseHeaders={
                    @ResponseHeader(name="code",description = " 0成功 1失败"),
                    @ResponseHeader(name="data",description = "   "),
                    @ResponseHeader(name="msg",description = "失败原因") })

    })
    public void deleteCircleProduct(){
        String uid=getAttr("loginUid");
        String circleId=getPara("circleId");
        String productId=getPara("productId");
        ReqResponse<Record> r=new ReqResponse();
        FriendService friendService2=enhance(FriendService.class);
        try {
            friendService2.deleteCircleProduct(uid,productId,circleId);
        }catch (Exception e){
            e.printStackTrace();
            r.setCode(1);
        }
        renderJson(r);
    }

    @ApiOperation(url = "/v1/friend/updateGroupRemind", tag = "friend", httpMethod = "post",description = "乐友-修改圈子提醒")
    @Params({
            @Param(name = "loginUid", description = "当前用户id", required = true, dataType = "string"),
            @Param(name = "remind", description = "1开启消息提醒0否", required = true, dataType = "string"),
            @Param(name = "circleId", description = "圈子Id", required = true, dataType = "string")
    })
    @ApiResponses({
            @ApiResponse(code=200,message="成功",responseHeaders={
                    @ResponseHeader(name="code",description = " 0成功 1失败"),
                    @ResponseHeader(name="data",description = "   "),
                    @ResponseHeader(name="msg",description = "失败原因") })

    })
    public void updateGroupRemind(){
        String uid=getAttr("loginUid");
        String remind=getPara("remind");
        String circleId=getPara("circleId");
        ReqResponse<Record> r=new ReqResponse();
        FriendService friendService2=enhance(FriendService.class);
        try {
            friendService2.updateGroupRemind(uid,circleId,remind);
        }catch (Exception e){
            e.printStackTrace();
            r.setCode(1);
        }
        renderJson(r);
    }
    @ApiOperation(url = "/v1/friend/getFriendDynamic", tag = "friend", httpMethod = "post",description = "乐友-好友动态-列表")
    @Params({
            @Param(name = "loginUid", description = "当前用户id", required = true, dataType = "string"),
            @Param(name = "type", description = "1关注2好友3我的动态", required = true, dataType = "string"),
            @Param(name = "pageNumber", description = "页码", required = true, dataType = "string")
    })
    @ApiResponses({
            @ApiResponse(code=200,message="成功",responseHeaders={
                    @ResponseHeader(name="code",description = " 0成功 1失败"),
                    @ResponseHeader(name="data",description = "{ type 1自媒体 2集市 3圈子 name用户名称 headImg用户头像 uid 用户id utype用户类型 mediaId 自媒体id  sex 性别 title 标题 createDate 发布时间 categoryName 分类名称 coverImgSrc图片 praiseCount 点赞数 commentCount 评论数 }"),
                    @ResponseHeader(name="msg",description = "失败原因") })

    })
    public void getFriendDynamic(){
        int pageNumber=getParaToInt("pageNumber");
        String uid=getAttr("loginUid");
        String type=getPara("type");
        ReqResponse<Page<Record>> r=new ReqResponse();
        Page<Record> records=null;
        if(type.equals("1")){
            records=friendService.getFriendFollowDynamic(pageNumber, uid);
        }
        else  if(type.equals("2")){
            records= friendService.getFriendDynamic(pageNumber, uid);
        }
        else  if(type.equals("3")){
            records= friendService.getMyDynamic(pageNumber, uid);
        }
        r.setData(records);
        renderJson(r);
    }
    @ApiOperation(url = "/v1/friend/getPost", tag = "friend", httpMethod = "post",description = "乐友-帖子详情")
    @Params({

            @Param(name = "loginUid", description = "当前用户id", required = true, dataType = "string"),
            @Param(name = "postId", description = "帖子Id", required = true, dataType = "string")
    })
    @ApiResponses({
            @ApiResponse(code=200,message="成功",responseHeaders={
                    @ResponseHeader(name="code",description = " 0成功 1失败"),
                    @ResponseHeader(name="data",description = " postId   title 标题 content 内容 isTop 1是置顶0否 " +
                            "isSelected 1是精选0否 isNotice 1是公告0否 isPraise 1点赞0没点赞 praiseCount点赞数 createDate 创建时间 name 圈子名称" +
                            "uid 帖子用户id uName 用户名称 headImg 用户头像 isPostUser 1是帖主0否 isCircleUser 1是圈主0否"),
                    @ResponseHeader(name="msg",description = "失败原因") })

    })
    @Clear
    public void getPost(){

        String token =  getPara("loginUid");

        String uid="";
        if (StrKit.notBlank(token)) {
            Map<String, Claim> map = JwtUtil.unsign(token);
            if (map != null) {
                uid= map.get("user_id").asString();
            }
        }
        String postId=getPara("postId");

        ReqResponse<Record> r=new ReqResponse();

        Record recor=  friendService.getPost(uid,postId);

        r.setData(recor);
        renderJson(r);
    }
    @ApiOperation(url = "/v1/friend/praisePost", tag = "friend", httpMethod = "post",description = "乐友-点赞")
    @Params({
            @Param(name = "state", description = "1点赞0取消", required = true, dataType = "string"),
            @Param(name = "loginUid", description = "当前用户id", required = true, dataType = "string"),
            @Param(name = "postId", description = "帖子Id", required = true, dataType = "string")
    })
    @ApiResponses({
            @ApiResponse(code=200,message="成功",responseHeaders={
                    @ResponseHeader(name="code",description = " 0成功 1失败"),
                    @ResponseHeader(name="data",description = "  praiseCount 点赞总数 "),
                    @ResponseHeader(name="msg",description = "失败原因") })

    })
    public void praisePost(){
        String state=getPara("state");
        String uid=getAttr("loginUid");
        String postId=getPara("postId");

        ReqResponse<Record> r=new ReqResponse();

        Record record= friendService.praisePost(uid,postId,state);
         r.setData(record);

        renderJson(r);
    }
    @ApiOperation(url = "/v1/friend/forwardPost", tag = "friend", httpMethod = "post",description = "乐友-帖子分享")
    @Params({
            @Param(name = "loginUid", description = "当前用户id", required = true, dataType = "string"),
            @Param(name = "title", description = "标题", required = true, dataType = "string"),
            @Param(name = "model", description = "类型 1视频，2广告，3游记，4帖子，5圈子，6个人，7城市，8企业，9简历", required = true, dataType = "string"),
            @Param(name = "modelId", description = "id", required = true, dataType = "string"),
            @Param(name = "circleId", description = "圈子id", required = true, dataType = "string"),

            @Param(name = "coverImgSrc", description = "封面图片", required = false, dataType = "string"),
            @Param(name = "modelName", description = "模块标题", required = true, dataType = "string"),
    })
    @ApiResponses({
            @ApiResponse(code=200,message="成功",responseHeaders={
                    @ResponseHeader(name="code",description = " 0成功 1失败"),
                    @ResponseHeader(name="data",description = "  "),
                    @ResponseHeader(name="msg",description = "失败原因") })

    })
    public void forwardPost(){
        String uid=getAttr("loginUid");
        String title=getPara("title");
        String model=getPara("model");
        String modelId=getPara("modelId");
        String coverImgSrc=getPara("coverImgSrc");
        String modelName=getPara("modelName");
        String circleId=getPara("circleId");

        ReqResponse<Record> r=new ReqResponse();

         friendService.forwardPost(uid,title,model,modelId,coverImgSrc,modelName,circleId);

        renderJson(r);
    }
    @ApiOperation(url = "/v1/friend/deletePost", tag = "friend", httpMethod = "post",description = "乐友-删除帖子")
    @Params({

            @Param(name = "loginUid", description = "当前用户id", required = true, dataType = "string"),
            @Param(name = "postId", description = "帖子Id", required = true, dataType = "string"),
            @Param(name = "delType", description = "删除类型 1系统 2圈主 3自己", required = true, dataType = "string")

    })
    @ApiResponses({
            @ApiResponse(code=200,message="成功",responseHeaders={
                    @ResponseHeader(name="code",description = " 0成功 1失败"),
                    @ResponseHeader(name="data",description = "   "),
                    @ResponseHeader(name="msg",description = "失败原因") })

    })
    public void deletePost(){

        String uid=getAttr("loginUid");
        String postId=getPara("postId");
        String delType=getPara("delType");

        ReqResponse r=new ReqResponse();

         friendService.deletePost(uid,postId,delType);

        renderJson(r);
    }
    @ApiOperation(url = "/v1/friend/setTop", tag = "friend", httpMethod = "post",description = "乐友-设置置顶")
    @Params({
            @Param(name = "state", description = "1设为置顶 0取消置顶", required = true, dataType = "string"),
            @Param(name = "loginUid", description = "当前用户id", required = true, dataType = "string"),
            @Param(name = "postId", description = "圈子Id", required = true, dataType = "string")
    })
    @ApiResponses({
            @ApiResponse(code=200,message="成功",responseHeaders={
                    @ResponseHeader(name="code",description = " 0成功 1失败"),
                    @ResponseHeader(name="data",description = "  "),
                    @ResponseHeader(name="msg",description = "失败原因") })

    })
    public void setTop(){

        String uid=getAttr("loginUid");
        String state=getPara("state");
        String postId=getPara("postId");

        ReqResponse<String> r=new ReqResponse();
        try {
            friendService.setTop(uid,state,postId);
        }catch (Exception e){
            e.printStackTrace();
            r.setCode(1);
        }
        r.setData("");
        renderJson(r);
    }
    @ApiOperation(url = "/v1/friend/setSelected", tag = "friend", httpMethod = "post",description = "乐友-设置精选")
    @Params({
            @Param(name = "state", description = "1设为精选 0取消精选", required = true, dataType = "string"),
            @Param(name = "loginUid", description = "当前用户id", required = true, dataType = "string"),
            @Param(name = "postId", description = "圈子Id", required = true, dataType = "string")
    })
    @ApiResponses({
            @ApiResponse(code=200,message="成功",responseHeaders={
                    @ResponseHeader(name="code",description = " 0成功 1失败"),
                    @ResponseHeader(name="data",description = "  "),
                    @ResponseHeader(name="msg",description = "失败原因") })

    })
    public void setSelected(){

        String uid=getAttr("loginUid");
        String state=getPara("state");
        String postId=getPara("postId");

        ReqResponse<String> r=new ReqResponse();
        try {
            friendService.setSelected(uid,state,postId);
        }catch (Exception e){
            e.printStackTrace();
            r.setCode(1);
        }
        r.setData("");
        renderJson(r);
    }
    @ApiOperation(url = "/v1/friend/setNotice", tag = "friend", httpMethod = "post",description = "乐友-设置公告")
    @Params({
            @Param(name = "state", description = "1设为公告 0取消公告", required = true, dataType = "string"),
            @Param(name = "loginUid", description = "当前用户id", required = true, dataType = "string"),
            @Param(name = "postId", description = "圈子Id", required = true, dataType = "string")
    })
    @ApiResponses({
            @ApiResponse(code=200,message="成功",responseHeaders={
                    @ResponseHeader(name="code",description = " 0成功 1失败"),
                    @ResponseHeader(name="data",description = "  "),
                    @ResponseHeader(name="msg",description = "失败原因") })

    })
    public void setNotice(){

        String uid=getAttr("loginUid");
        String state=getPara("state");
        String postId=getPara("postId");

        ReqResponse<String> r=new ReqResponse();
        try {
            friendService.setNotice(uid,state,postId);
        }catch (Exception e){
            e.printStackTrace();
            r.setCode(1);
        }
        r.setData("");
        renderJson(r);
    }

   /* @ApiOperation(url = "/v1/friend/getCommentsByPostId", tag = "friend", httpMethod = "post",description = "乐友-帖子-评论列表")
    @Params({
            @Param(name = "postId", description = "帖子id", required = true, dataType = "string"),
            @Param(name = "pageNumber", description = "页码", required = true, dataType = "string")
    })
    @ApiResponses({
            @ApiResponse(code=200,message="成功",responseHeaders={
                    @ResponseHeader(name="code",description = " 0成功 1失败"),
                    @ResponseHeader(name="data",description = "  totalRow 总行数  pageNumber第几页 firstPage 是否第一页 lastPage 是否最后一页 totalPage 总页数 pageSize每页条数  list[{" +
                            "id 记录id userId 评论用户 uName 评论用户名称 headImg 评论用户头像 content 内容 " +
                            "replyUserId 回复id rName回复用户名称 rheadImg回复用户头像 createDate 创建时间" +
                            " commentId 回复评论id }] "),
                    @ResponseHeader(name="msg",description = "失败原因") })

    })
    public void getCommentsByPostId(){
        String id=getPara("postId");
        int pageNumber=getParaToInt("pageNumber");
        ReqResponse<Page<Record>> r=new ReqResponse();
        Page<Record> record= friendService.getCommentsByPostId(id,pageNumber);
        r.setData(record);
        renderJson(r);
    }*/
   @ApiOperation(url = "/v1/friend/postComment", tag = "friend", httpMethod = "post",description = "发表评论")
   @Params({
           @Param(name = "loginUid", description = "当前用户id", required = true, dataType = "string"),
           @Param(name = "commentId", description = "评论id", required = false, dataType = "string"),
           @Param(name = "ruserId", description = "回复用户id", required = false, dataType = "string"),
           @Param(name = "content", description = "评论内容", required = true, dataType = "string"),
           @Param(name = "postId", description = "帖子id", required = true, dataType = "string"),

   })
   @ApiResponses({
           @ApiResponse(code=200,message="成功",responseHeaders={
                   @ResponseHeader(name="data",description = " 总点赞数"),
                   @ResponseHeader(name="code",description = " 0成功 1失败"),
                   @ResponseHeader(name="msg",description = "失败原因") })

   })

   public void postComment(){
       FriendService friendService2 = enhance(FriendService.class);
       String loginUid=getAttr("loginUid");
       String postId=getPara("postId");
       String commentId=getPara("commentId");
       String ruserId=getPara("ruserId");
       String content=getPara("content");
       ReqResponse<String> r=new ReqResponse();
       try {
           friendService2.postComment(loginUid,commentId,ruserId,content,postId);

       }catch (Exception e){
           e.printStackTrace();
           r.setCode(1);
           r.setMsg("操作失败");
       }
       renderJson(r);
   }
    @ApiOperation(url = "/v1/friend/getInfoPostCommentList", tag = "friend", httpMethod = "post",description = "乐友-帖子-获取评论列表")
    @Params({
            @Param(name = "postId", description = "帖子id", required = true, dataType = "string"),
            @Param(name = "loginUid", description = "当前登录用户id", required = true, dataType = "string"),
            @Param(name = "pageNumber", description = "页码", required = true, dataType = "string")
    })
    @ApiResponses({
            @ApiResponse(code=200,message="成功",responseHeaders={
                    @ResponseHeader(name="code",description = " 0成功 1失败"),
                    @ResponseHeader(name="data",description = "  totalRow 总行数  pageNumber第几页 firstPage 是否第一页 lastPage 是否最后一页 totalPage 总页数 pageSize每页条数  list[{" +
                            "commentId 评论id userId 评论用户 uName 评论用户名称" +
                            " headImg 评论用户头像 content 内容 praiseState 1点赞0未点赞 " +
                            "  commentCount 回复总数 praiseCount 点赞数 createDate 创建时间 }] "),
                    @ResponseHeader(name="msg",description = "失败原因") })

    })
    public void getInfoPostCommentList(){
        String postId=getPara("postId");
        String loginUid=getAttr("loginUid");
        int pageNumber=getParaToInt("pageNumber");
        ReqResponse<Page<Record>> r=new ReqResponse();
        Page<Record> record= friendService.getInfoPostCommentList(postId,pageNumber,loginUid);
        r.setData(record);
        renderJson(r);
    }
    @ApiOperation(url = "/v1/friend/getInfoPostCommentByCommentId", tag = "friend", httpMethod = "post",description = "乐友-帖子-获取评论详情")
    @Params({
            @Param(name = "commentId", description = "评论id", required = true, dataType = "string"),
            @Param(name = "loginUid", description = "当前登录用户id", required = true, dataType = "string"),
    })
    @ApiResponses({
            @ApiResponse(code=200,message="成功",responseHeaders={
                    @ResponseHeader(name="code",description = " 0成功 1失败"),
                    @ResponseHeader(name="data",description =  "commentId 评论id userId 评论用户 uName 评论用户名称" +
                            " headImg 评论用户头像 content 内容 praiseState 1点赞0未点赞 " +
                            "  commentCount 回复总数 praiseCount 点赞数 createDate 创建时间  "),
                    @ResponseHeader(name="msg",description = "失败原因") })

    })
    public void getInfoPostCommentByCommentId(){
        String postId=getPara("commentId");
        String loginUid=getAttr("loginUid");

        ReqResponse< Record> r=new ReqResponse();
        Record  record= friendService.getInfoPostCommentById(postId,loginUid);
        r.setData(record);
        renderJson(r);
    }
    @ApiOperation(url = "/v1/friend/getInfoPostCommentReplyList", tag = "friend", httpMethod = "post",description = "乐友-帖子-获取评论回复列表")
    @Params({
            @Param(name = "commentId", description = "评论id", required = true, dataType = "string"),
            @Param(name = "loginUid", description = "当前登录用户id", required = true, dataType = "string"),
            @Param(name = "pageNumber", description = "页码", required = true, dataType = "string")
    })
    @ApiResponses({
            @ApiResponse(code=200,message="成功",responseHeaders={
                    @ResponseHeader(name="code",description = " 0成功 1失败"),
                    @ResponseHeader(name="data",description = "  totalRow 总行数  pageNumber第几页 firstPage 是否第一页 lastPage 是否最后一页 totalPage 总页数 pageSize每页条数  list[{" +
                            "commentId 评论id userId  用户 uName  用户名称 headImg  用户头像" +
                            "  ruName 回复用户名称    content 回复内容  createDate 回复创建时间 }] "),
                    @ResponseHeader(name="msg",description = "失败原因") })

    })
    public void getInfoPostCommentReplyList(){
        String commentId=getPara("commentId");
        int pageNumber=getParaToInt("pageNumber");
        ReqResponse<Page<Record>> r=new ReqResponse();
        Page<Record> record= friendService.getInfoPostCommentReplyList(commentId,pageNumber);
        r.setData(record);
        renderJson(r);
    }

    @ApiOperation(url = "/v1/friend/praisePostComment", tag = "friend", httpMethod = "post",description = "乐友-帖子-评论点赞")
    @Params({
            @Param(name = "commentId", description = "评论id", required = true, dataType = "string"),
            @Param(name = "loginUid", description = "当前登录用户id", required = true, dataType = "string"),
            @Param(name = "state", description = "1点赞0取消点赞", required = true, dataType = "string")
    })
    @ApiResponses({
            @ApiResponse(code=200,message="成功",responseHeaders={
                    @ResponseHeader(name="code",description = " 0成功 1失败"),
                    @ResponseHeader(name="data",description = "  "),
                    @ResponseHeader(name="msg",description = "失败原因") })

    })
    public void praisePostComment(){
        String commentId=getPara("commentId");
        String loginUid=getAttr("loginUid");
        int state=getParaToInt("state");
        ReqResponse<Record> r=new ReqResponse();
        FriendService advService=enhance(FriendService.class);
        r.setData(advService.praisePostComment(commentId,loginUid,state) );
        renderJson(r);
    }
    @ApiOperation(url = "/v1/friend/savePostPhoto", tag = "friend", httpMethod = "post",description = "乐友-发布帖子图片")
    @Params({
            @Param(name = "loginUid", description = "当前用户id", required = true, dataType = "string"),
            @Param(name = "imgSrc", description = "图片文件", required = true, dataType = "string")
    })
    @ApiResponses({
            @ApiResponse(code=200,message="成功",responseHeaders={
                    @ResponseHeader(name="code",description = " 0成功 1失败"),
                    @ResponseHeader(name="data",description = "文件路径"),
                    @ResponseHeader(name="msg",description = "失败原因") })

    })
    public void savePostPhoto(){
        UploadFile uf=getFile("imgSrc");
        getResponse().addHeader("Access-Control-Allow-Origin", "*");


        ReqResponse<String> r=new ReqResponse();

        try {
            String coverImgSrc= USERFILES_POST_BASE_URL +DateUtil.FormatDateMMDD()+"/";
            coverImgSrc=getFilePath(coverImgSrc,uf);
            //FileUtils.copyFileUsingFileChannels(uf.getFile(), file);
            r.setData( PropKit.get("fileServer")+coverImgSrc);
        }catch (Exception e){
            e.printStackTrace();
            r.setCode(1);
        }


        renderJson(r);
    }
    @ApiOperation(url = "/v1/friend/savePost", tag = "friend", httpMethod = "post",description = "乐友-发布帖子")
    @Params({
            @Param(name = "loginUid", description = "当前用户id", required = true, dataType = "string"),
            @Param(name = "circleId", description = "圈子id", required = true, dataType = "string"),
            @Param(name = "title", description = "标题", required = true, dataType = "string"),
            @Param(name = "content", description = "内容", required = true, dataType = "string")
    })
    @ApiResponses({
            @ApiResponse(code=200,message="成功",responseHeaders={
                    @ResponseHeader(name="code",description = " 0成功 1失败"),
                    @ResponseHeader(name="data",description = " "),
                    @ResponseHeader(name="msg",description = "失败原因") })

    })
    public void savePost(){
        String loginUid=getAttr("loginUid");
        String circleId=getPara("circleId");
        String title=getPara("title");
        String content=getPara("content");
        ReqResponse<String> r=new ReqResponse();
        friendService.savePost(loginUid,circleId,title,content);
        renderJson(r);
    }
    @ApiOperation(url = "/v1/friend/getCirclePost", tag = "friend", httpMethod = "post",description = "乐友-帖子列表")
    @Params({
            @Param(name = "loginUid", description = "当前用户id", required = true, dataType = "string"),
            @Param(name = "circleId", description = "圈子id", required = true, dataType = "string"),
            @Param(name = "pageNumber", description = "页码", required = true, dataType = "string"),
            @Param(name = "state", description = "1 最新评论 2最新发表 3精华", required = true, dataType = "string")
    })
    @ApiResponses({
            @ApiResponse(code=200,message="成功",responseHeaders={
                    @ResponseHeader(name="code",description = " 0成功 1失败"),
                    @ResponseHeader(name="data",description = " postId 帖子id title 标题  type 帖子类型 1写2转发3分享 isSelected 1精选0否 " +
                            "praiseCount 点赞数 commitCount 评论数 isPraise 1点赞0否  coverImgSrc 分享图片 model 类型 1视频，2广告，3游记，4帖子，5圈子，6个人，7城市，8企业，9简历 modelId  模块id modelName 模块名称" +
                            "staticAdv { coverImgSrc 图片地址 coverLink 图片链接  imgSrc 视频地址 ,imgLinks 视频链接 imgRank 图片排序 title 标题 imgNote 副标题 type 类型  1自媒体 2企业广告3城市广告4传统文化 }"),
                    @ResponseHeader(name="msg",description = "失败原因") })

    })
    public void getCirclePost(){
        String loginUid=getAttr("loginUid");
        String circleId=getPara("circleId");
        String state=getPara("state");
        int pageNumber=getParaToInt("pageNumber");
        ReqResponse<Page<Record>> r=new ReqResponse();

        Page<Record> p= friendService.getCirclePost(loginUid,circleId,pageNumber,state);
//        List<Record>  statics= advService.getStaticListByType("4");
        for (Record record1:p.getList()
                ) {
            record1.set("staticAdv", null);
//            for (Record static1:statics
//                    ) {
//
//                if(0==MathRandom.PercentageRandom()) {
//                    record1.set("staticAdv", static1);
//                }
//            }

        }
        r.setData(p);
        renderJson(r);
    }
    @ApiOperation(url = "/v1/friend/buyBooth", tag = "friend", httpMethod = "post",description = "购买展位")
    @Params({
            @Param(name = "loginUid", description = "当前用户id", required = true, dataType = "string"),
            @Param(name = "circleId", description = "圈子id", required = true, dataType = "string"),
    })
    @ApiResponses({
            @ApiResponse(code=200,message="成功",responseHeaders={
                    @ResponseHeader(name="code",description = " 0成功 1失败"),
                    @ResponseHeader(name="data",description = " "),
                    @ResponseHeader(name="msg",description = "失败原因") })

    })
    public void buyBooth(){
        String loginUid=getAttr("loginUid");
        String circleId=getPara("circleId");

        ReqResponse<String> r=new ReqResponse();
        try {
            friendService.buyBooth(loginUid,circleId);
        } catch (Exception e) {
            e.printStackTrace();
            r.setMsg("乐币不够");
            r.setCode(1);
        }
        renderJson(r);
    }
    @ApiOperation(url = "/v1/friend/getUserInfoByUid", tag = "friend", httpMethod = "post",description = "用户信息")
    @Params({
            @Param(name = "loginUid", description = "当前用户id", required = true, dataType = "string"),
            @Param(name = "uid", description = "用户id", required = true, dataType = "string"),
    })
    @ApiResponses({
            @ApiResponse(code=200,message="成功",responseHeaders={
                    @ResponseHeader(name="code",description = " 0成功 1失败"),
                    @ResponseHeader(name="data",description = " uid  name 名称 headImg 头像   sex 1男2女  level 级别"),
                    @ResponseHeader(name="msg",description = "失败原因") })

    })
    public void getUserInfoByUid(){
        String loginUid=getAttr("loginUid");
        String uid=getPara("uid");

        ReqResponse<Record> r=new ReqResponse();

          r.setData(friendService.getUserInfoByUid(loginUid,uid));

        renderJson(r);
    }

    @ApiOperation(url = "/v1/friend/search", tag = "friend", httpMethod = "post",description = "乐友-搜索")
    @Params({
            @Param(name = "loginUid", description = "当前用户id", required = true, dataType = "string"),
            @Param(name = "name", description = "内容", required = true, dataType = "string")
    })
    @ApiResponses({
            @ApiResponse(code=200,message="成功",responseHeaders={
                    @ResponseHeader(name="code",description = " 0成功 1失败"),
                    @ResponseHeader(name="data",description = " "),
                    @ResponseHeader(name="msg",description = "失败原因") })

    })
    public void search(){
        String loginUid=getAttr("loginUid");
        String name=getPara("name");

        ReqResponse< Record> r=new ReqResponse();
        r.setData(friendService.search(loginUid,name));
        renderJson(r);
    }

    @ApiOperation(url = "/v1/friend/searchfriendList", tag = "friend", httpMethod = "post",description = "乐友-搜索好友")
    @Params({
            @Param(name = "loginUid", description = "当前用户id", required = true, dataType = "string"),
            @Param(name = "name", description = "内容", required = true, dataType = "string")
    })
    @ApiResponses({
            @ApiResponse(code=200,message="成功",responseHeaders={
                    @ResponseHeader(name="code",description = " 0成功 1失败"),
                    @ResponseHeader(name="data",description = "name 名称 level 等级 headImg  头像uid 用户id token 聊天token type 类型  1自媒体 2企业广告3城市广告4传统文化 sex 1男2女 "),
                    @ResponseHeader(name="msg",description = "失败原因") })

    })
    public void searchfriendList(){
        String loginUid=getAttr("loginUid");
        String name=getPara("name");

        ReqResponse< List<Record>> r=new ReqResponse();
        r.setData(friendService.searchfriendList(loginUid,name));
        renderJson(r);
    }

    @ApiOperation(url = "/v1/friend/searchcirclenotinList", tag = "friend", httpMethod = "post",description = "乐友-搜索未加入的圈子")
    @Params({
            @Param(name = "loginUid", description = "当前用户id", required = true, dataType = "string"),
            @Param(name = "name", description = "内容", required = true, dataType = "string")
    })
    @ApiResponses({
            @ApiResponse(code=200,message="成功",responseHeaders={
                    @ResponseHeader(name="code",description = " 0成功 1失败"),
                    @ResponseHeader(name="data",description = "coverImgSrc 图片 circleId 圈子id circleName 圈子名称categoryName 圈子分类 userCount圈子人数 "),
                    @ResponseHeader(name="msg",description = "失败原因") })

    })
    public void searchcirclenotinList(){
        String loginUid=getAttr("loginUid");
        String name=getPara("name");

        ReqResponse< List<Record>> r=new ReqResponse();
        r.setData(friendService.searchcirclenotinList(loginUid,name));
        renderJson(r);
    }

    @ApiOperation(url = "/v1/friend/searchcircleList", tag = "friend", httpMethod = "post",description = "乐友-搜索圈子")
    @Params({
            @Param(name = "loginUid", description = "当前用户id", required = true, dataType = "string"),
            @Param(name = "name", description = "内容", required = true, dataType = "string")
    })
    @ApiResponses({
            @ApiResponse(code=200,message="成功",responseHeaders={
                    @ResponseHeader(name="code",description = " 0成功 1失败"),
                    @ResponseHeader(name="data",description = "coverImgSrc 图片 circleId 圈子id circleName 圈子名称categoryName 圈子分类 userCount圈子人数 "),
                    @ResponseHeader(name="msg",description = "失败原因") })

    })
    public void searchcircleList(){
        String loginUid=getAttr("loginUid");
        String name=getPara("name");

        ReqResponse< List<Record>> r=new ReqResponse();
        r.setData(friendService.searchcircleList(loginUid,name));
        renderJson(r);
    }
}
